package org.fhawk.tinyspring.mvc;


import org.fhawk.tinyspring.HelperLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.time.LocalDate;

/**
 * 容器监听器
 *
 * @author huangyong
 * @since 1.0
 */
@WebListener
public class ContainerListener implements ServletContextListener {
    private static Logger logger = LoggerFactory.getLogger(ContainerListener.class);

    /**
     * 当容器初始化时调用
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // 初始化相关 Helper 类
        try {
            HelperLoader.init();
        } catch (Exception e) {
            logger.error("框架初始化失败", e);
        }

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        logger.info("{}-服务器关闭", LocalDate.now());
    }
}
